﻿function InitMarked()
{
	var renderer = new Markdown.marked.Renderer();
	renderer.listitem = function(text) {
		if (/^ *\[[xX ]\]\s*/.test(text)) {
			text = text
				.replace(/^\s*\[ \] */, '<input type="checkbox" disabled> ')
				.replace(/^\s*\[[xX]\] */, '<input type="checkbox" checked disabled> ');
			return '<li style="list-style: none">' + text + '</li>';
		} else {
			return '<li>' + text + '</li>';
		}
	};

	renderer.code = function(code, language){
		code = code.replace(/</g, '&lt;').replace(/>/g, '&gt;');
		if(language=='' || language==undefined)
			return '<pre class="prettyprint">'+code+'</pre>';
		return '<pre class="prettyprint lang-'+ language +'">'+code+'</pre>';
	};

	Markdown.marked.setOptions({
		renderer: renderer,
		footnotes : true
	});
}

InitMarked();

var css_preview=SCRIPT_PATH+"\\preview.css";
var css_code=SCRIPT_PATH+"\\prettify.css";
var js_highlight=SCRIPT_PATH+"\\prettify.js";
var js_toc=SCRIPT_PATH+"\\toc.js";
var js_query=SCRIPT_PATH+"\\jquery-1.11.3.min.js";

var doc = App.ActiveDoc;
var rs = Markdown.marked( doc.Text );

var content="\
<!doctype html>\n\
<html>\n\
<head>\n\
<meta charset='GBK'/>\n\
<link rel='stylesheet' type='text/css' href='github.css'>\n\
<title>Markdown_Preview</title>\n\
</head>\n\
<body>\n\
<div id='content'>\n" + rs + "</div>\n\
</body>\n\
</html>";
